package com.back.controller;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.back.model.Statistic;
import com.back.utils.Log;

@RestController
@RequestMapping("/home")
public class HomeController {

    @PostMapping("/getStatistic")
    public Statistic getStatistic(@RequestBody String typeEn) {
        Log.info(getClass(), "getStatistic被调用 type: {}", typeEn);
        String type = typeEn.replace("\"", "");

        Statistic statistic = new Statistic();
        if (type.equals("download")) {
            Log.info(getClass(), "type download");
            statistic.setLabel("月度下载数据");
            statistic.setLabels(new String[] { "一月", "二月", "三月", "四月", "五月" });
            statistic.setData(new int[] { 10, 20, 30, 40, 50 });
        }
        if (type.equals("quantity")) {
            Log.info(getClass(), "type quantity");
            statistic.setLabel("Example Labe2");
            statistic.setLabels(new String[] { "文档", "软件", "工具", "视频", "音频", "游戏", "设计", "编程" });
            statistic.setData(new int[] { 20, 10, 10, 10, 10, 15, 15, 10 });
        }
        return statistic;
    }

}
